const config = require('core/config');
App({
  globalData: {
    openid: '',
    userInfo: null
  },
  onLaunch: function () {
    let userInfo = wx.getStorageSync('userInfo') || null
    if (userInfo != null) {
      this.globalData.userInfo = userInfo
    }
    let openid = wx.getStorageSync('openid') || null
    if (openid != null) {
      this.globalData.openid = openid
    }
    wx.cloud.init({
      // env 参数说明：
      //   env 参数决定接下来小程序发起的云开发调用（wx.cloud.xxx）会默认请求到哪个云环境的资源
      //   此处请填入环境 ID, 环境 ID 可打开云控制台查看
      //   如不填则使用默认环境（第一个创建的环境）
      env: 'tlradio-2gokkusy0fba44c3',
      traceUser: true,
    })
    wx.cloud.callFunction({ //获取用户openid
      name: 'openapi',
      data: {
        action: 'getOpenData'
      },
      success: r => {
        // console.log(r)
        let openid = r.result.openid
        wx.setStorageSync('openid', openid)
        this.globalData.openid = openid
      },
      fail: r => {
        console.log(r)
      }
    })
    this.globalData = {
      key: '739c5d791219435ea254986bb41d5d45',
      type: 0,
      requestUrl: {
        weather: 'https://free-api.heweather.com/s6/weather',
      },
    }
    wx.getSystemInfo({
      success: e => {
        this.globalData.StatusBar = e.statusBarHeight;
        let custom = wx.getMenuButtonBoundingClientRect();
        this.globalData.Custom = custom;
        this.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
      }
    })
    this.update()
  },

  update: function () {
    let um = wx.getUpdateManager()
    um.onCheckForUpdate(res => res.hasUpdate && um.onUpdateReady(() => um.applyUpdate()))
  },
})